package 左哥算法.ch07图;

import java.util.LinkedList;
import java.util.Queue;

public class Ch03几道宽度遍历的题目 {

    /**
     * 给你一头
     */
    public void test01(){

    }
    public int fun1(int s,int e){
        Queue<Integer> queue=new LinkedList<Integer>();
        int[] path=new int[Math.max(s,e)*2];    //记录走到该位置的最短时间,
        queue.add(s);
        path[s]=1;
        int[] directions=new int[3];    //三种尝试方式
        while (!queue.isEmpty()) {
            Integer curr = queue.poll();
            if (curr==e){
                break;
            }
            directions[0]=curr+1;
            directions[1]=curr-1;
            directions[2]=curr*2;
            for (int d : directions) {
                if (d>0&&d<path.length&&path[d]==0){
                    path[d]=path[curr]+1;
                    queue.add(d);
                }
            }
        }
        return path[e]-1;
    }
}
